import {
  Body,
  Controller,
  Delete,
  Get,
  Param, ParseUUIDPipe,
  Patch,
  Post,
  Query,
  UseGuards,
} from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
import {
  BrandAdminCreateDto,
  BrandAdminIndexDto,
  BrandAdminUpdateDto,
} from './brand.dto';
import { BrandService } from './brand.service';
import { getPager } from "@/common/pager-response";
import { AdminAuthGuard } from "@/common/auth/admin-auth.guard";
import { BrandAdminIndexResult } from "@/module/brand/brand.result";
import { PageResult } from "common/interface";
import { ApiPaginatedOkResponse } from "@/common/pager-response/api-paginated-ok-response.decorator";

@Controller('/v1/admin/brands')
@ApiTags('Brand_admin')
@UseGuards(AdminAuthGuard)
export class BrandV1AdminController {
  constructor(private readonly brandService: BrandService) {
  }

  @Get('/')
  @ApiOperation({ summary: '列表查询' })
  @ApiPaginatedOkResponse(BrandAdminIndexResult)
  async index(@Query() query: BrandAdminIndexDto): Promise<PageResult<BrandAdminIndexResult>> {
    const res = await this.brandService.adminIndex(query);
    return getPager(res[0], res[1]);
  }

  @Post('/')
  @ApiOperation({ summary: '新增' })
  async create(@Body() body: BrandAdminCreateDto): Promise<void> {
    await this.brandService.adminCreate(body);
    return;
  }

  @Patch('/:uuid')
  @ApiOperation({ summary: '修改' })
  async update(
    @Body() body: BrandAdminUpdateDto,
    @Param('uuid', ParseUUIDPipe) uuid: string,
  ): Promise<void> {
    await this.brandService.adminUpdate(body, uuid);
    return;
  }

  @Delete('/:uuid')
  @ApiOperation({ summary: '删除' })
  async destroy(@Param('uuid', ParseUUIDPipe) uuid: string): Promise<void> {
    await this.brandService.adminDestroy(uuid);
    return;
  }
}
